﻿<MudDialog>
    <TitleContent>
        <MudText Typo="Typo.h6">
            <MudIcon Icon="@Icons.Material.Filled.QuestionMark" Class="mb-n1" />
            @ConstantString.DeleteConfirmationTitle
        </MudText>
    </TitleContent>
    <DialogContent>
        <MudText>@ContentText</MudText>
    </DialogContent>
    <DialogActions>
        <MudButton StartIcon="@Icons.Material.Filled.Cancel" OnClick="Cancel" title="@ConstantString.Cancel">@ConstantString.Cancel</MudButton>
        <MudButton StartIcon="@Icons.Material.Outlined.Delete" Color="Color.Error"  title="@ConstantString.Delete" OnClick="Submit">@ConstantString.Confirm</MudButton>
    </DialogActions>
</MudDialog>

@code
{
    [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = default!;

    [EditorRequired][Parameter] public string? ContentText { get; set; }
    [EditorRequired][Parameter] public IRequest<Result> Command { get; set; } = default!;

    private async Task Submit()
    {
        var result = await Mediator.Send(Command);
        result.Match(
          ()=>
          {
              Snackbar.Add($"{ConstantString.DeleteSuccess}", Severity.Info);
              MudDialog.Close(DialogResult.Ok(true));
          },
          errors =>
          {
              Snackbar.Add($"{errors}", Severity.Error);
          }
        );
        
    }

    private void Cancel()
    {
        MudDialog.Cancel();
    }
}